package org.htmlparser.filters;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.tags.CompositeTag;
import org.htmlparser.util.NodeList;

public class HasChildFilter
  implements NodeFilter
{
  protected NodeFilter mChildFilter;
  protected boolean mRecursive;

  public HasChildFilter()
  {
    this(null);
  }

  public HasChildFilter(NodeFilter paramNodeFilter)
  {
    this(paramNodeFilter, false);
  }

  public HasChildFilter(NodeFilter paramNodeFilter, boolean paramBoolean)
  {
    setChildFilter(paramNodeFilter);
    setRecursive(paramBoolean);
  }

  public boolean accept(Node paramNode)
  {
    int i = 0;
    if (paramNode instanceof CompositeTag)
    {
      NodeList localNodeList = ((CompositeTag)paramNode).getChildren();
      if (localNodeList != null)
      {
        for (int j = 0; (i == 0) && (j < localNodeList.size()); ++j)
          if (getChildFilter().accept(localNodeList.elementAt(j)))
            i = 1;
        if ((i == 0) && (getRecursive()))
          for (int k = 0; (i == 0) && (k < localNodeList.size()); ++k)
            if (accept(localNodeList.elementAt(k)))
              i = 1;
      }
    }
    return i;
  }

  public NodeFilter getChildFilter()
  {
    return this.mChildFilter;
  }

  public boolean getRecursive()
  {
    return this.mRecursive;
  }

  public void setChildFilter(NodeFilter paramNodeFilter)
  {
    this.mChildFilter = paramNodeFilter;
  }

  public void setRecursive(boolean paramBoolean)
  {
    this.mRecursive = paramBoolean;
  }
}